from flask import Flask, render_template, request
from flask_sqlalchemy import SQLAlchemy
from src.web.service import search_service

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+mysqlconnector://palworld:eyDE7eFCxB8bJPBK@123.57.228.245:3306/palworld'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False  # 关闭对模型修改的跟踪
db = SQLAlchemy(app)

with app.app_context():
    # 初始化数据库
    db.init_app(app)


@app.route('/search', methods=['POST'])
def search():
    query = request.form['query']
    search_service.search_service(query)
    result = "这里是搜索结果"
    return result


@app.route('/')
def index():
    return render_template('index.html')


if __name__ == '__main__':
    app.run(port=2024, debug=True)
